<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        h1 {
            font-size: 1.3rem;
            font-weight: 300;
            color: rgb(153, 153, 153);
            text-align: center;
            width: 100%;
            height: 3rem;
            line-height: 3rem;
            border-bottom: 1px solid #dbdbdb;
            margin-bottom: 1rem;
        }

        body {
            background-color: #efefef;
        }

        .grit>div {
            display: grid;
            grid-template-columns: auto auto;
            justify-content: center;
            width: 100%;
        }

        .box {
            width: 10rem;
            height: 15rem;
            background-color: #ffffff;
            margin: .5rem;
            border-radius: .5rem;
            display: flex;
            flex-direction: column;
            position: relative;
        }

        .box img {
            width: 100%;
        }

        .box h2 {
            font-size: .6rem;
            font-weight: 400;
            width: 80%;
            margin-left: 10%;
            margin-top: .5rem;
            margin-right: 10%;
        }

        .box>div {
            position: absolute;
            bottom: 5%;
            width: 80%;
            left: 10%;
            display: flex;
            align-items: center;
        }

        .box .sp1 {
            color: red;
            font-size: 1.2rem;
        }

        .box .sp2 {
            font-size: .1rem;
            color: red;
            height: .5rem;
            /* border: .01rem solid red;
            font-weight: 200;
            padding: .1rem;
            border-radius: .8rem; */
        }

        .box a {
            color: #c2c2c2;
            font-size: .01rem;
            font-weight: 200;
            /* border: .01rem solid #c2c2c2; */
            padding: .1rem;
            border-radius: .8rem;
            text-decoration: none;
            height: .5rem;
            position: absolute;
            right: 0;
        }
    </style>
</head>

<body>
    <div id="app">
        <h1> {{title}} </h1>

        <div class="grit" @click="poiu" >
            <box></box>
        </div>
    </div>


    <script src="./js/vue.js"></script>
    <template id="box">
        <div>
            <div class="box" v-for="(imet,index) in arr" :key="imet.id" @click="gain(index)">
                <img :src="imet.url" alt="">
                <h2>{{imet.name}}</h2>
                <div>
                    <h6 class="sp1">{{imet.price | filtration}}</h6>
                    <h6 class="sp2">{{imet.sale}}</h6>
                    <a href="#">看相似</a>
                </div>
            </div>
        </div>
    </template>
    <script>
        const app = new Vue({
            el: "#app",
            data() {
                return {
                    title: "猜你喜欢",
                }
            },
            components: {
                'box': {
                    template: "#box",
                    data() {
                        return {
                            arr: [
                                { id: 0, name: "Redmi Note 11T Pro+", price: 2099, sale: "满减", url: "./img/1.webp" },
                                { id: 1, name: "Redmi Note 11T Pro", price: 2199, sale: "满减", url: "./img/2.webp" },
                                { id: 2, name: "Redmi Note 11SE", price: 2299, sale: "满减", url: "./img/3.webp" },
                                { id: 3, name: "Xiaomi Civi 1S", price: 3099, sale: "满减", url: "./img/4.webp" },
                                { id: 4, name: "Xiaomi Watch S1", price: 249, sale: "包邮", url: "./img/5.webp" },
                                { id: 5, name: "Xiaomi真无线降噪耳机3", price: 1099, sale: "包邮", url: "./img/6.webp" },
                                { id: 6, name: "Redmi手表2", price: 299, sale: "包邮", url: "./img/7.webp" },
                                { id: 7, name: "小手环6 NFC版", price: 399, sale: "包邮", url: "./img/8.webp" },
                                { id: 8, name: "小米电视", price: 2099, sale: "上新", url: "./img/9.webp" },
                                { id: 9, name: "小米电视6至尊版65英寸", price: 4099, sale: "上新", url: "./img/10.webp" },
                                { id: 10, name: "小米电视ES55 2022款", price: 3299, sale: "上新", url: "./img/11.webp" },
                                { id: 11, name: "米家全能扫拖机器人", price: 4599, sale: "上新", url: "./img/12.webp" },
                                { id: 12, name: "米家扫拖机器人2Pro", price: 2099, sale: "满减", url: "./img/13.webp" },
                            ],
                            num:""
                        }
                    },
                    methods: {
                        gain(i) {
                            this.num=this.arr[i].name
                        }
                    },
                    filters: {
                        filtration(val) {
                            return "￥" + val
                        }
                    }
                }
            },
            methods:{
                poiu(){
                    this.title=this.$children[0].num
                }
            }
        })
    </script>
</body>

</html>